package util;

import entity.People;
import entity.Student;
import org.junit.Test;

import java.util.Objects;
import java.util.logging.Logger;

public class ObjectsTest {

    private static final Logger logger = Logger.getLogger(String.valueOf(ObjectsTest.class));

    /**
     * Objects.equlas()
     */
    @Test
    public void testOne() {
        String strOne = null;
        String strTwo = null;
        boolean oneFlag = Objects.equals(strOne, strTwo);
        boolean flag = Objects.equals(strOne, strTwo);
        logger.info("-------> 结果为：" + flag);
        logger.info("-------> 结果为：" + oneFlag);
    }

    /**
     * Objects.equals()
     */
    @Test
    public void objectsEqual() {
        String strOne = null;
        String strTwo = null;
        if (Objects.equals(strOne, strTwo)) {
            logger.info("true");
        }
    }

    /**
     * Objects 校验参数非空和不空
     */
    @Test
    public void objectsRequireNonNull() {
        logger.info("校验参数为空和不为空！");
        String str = Objects.requireNonNull(null, "当前参数不能为空！");
        logger.info("参数信息：" + str);
    }

    /**
     * Objects toString()
     */
    @Test
    public void objectsToString() {
        People people = new People();
        people.setId(1001);
        // toString()方法
        String strPeopleOne = Objects.toString(people);
        logger.info(strPeopleOne);

        // 如果对象为空，则使用第二个参数
        String strPeopleTwo = Objects.toString(null, strPeopleOne);
        logger.info(strPeopleTwo);
    }

    @Test
    public void objectTestOne() {
        Student studentOne = new Student("张三", "1001");
        Student studentTwo = new Student("张三", "1001");
        logger.info(String.valueOf(studentOne.hashCode()));
        logger.info(String.valueOf(studentTwo.hashCode()));
        logger.info(String.valueOf(studentOne == studentTwo));
        logger.info(String.valueOf(studentOne.equals(studentTwo)));
    }

}
